/*流版签插件相关工具类*/


import PdfOffice from "@/plugins/office/extend/pdf-office";
import BaseOffice from "@/plugins/office/extend/base-office";
import OfdOffice from "@/plugins/office/extend/ofd-office";
import {BodyTypeEnums} from "@/plugins/data";
import WpsOffice from "@/plugins/office/extend/wps-office";

function getInstance({bodyType, zwIframe}) {
  if (`${bodyType}` === BodyTypeEnums.pdf.toString()) {
    return new PdfOffice();
  }
  if (zwIframe?.OfficeAPI?.officeType==='wps'){
    return new WpsOffice();
  }
  if(`${bodyType}` === BodyTypeEnums.ofd.toString()){
     return new OfdOffice();
  }
  let useWebOffice = zwIframe.useWebOffice && zwIframe.OfficeUtils.canUseWebOffice();
  if (!useWebOffice && zwIframe.clientMixNet === 'disable' && isOfficeBodyType(bodyType)) {
    return new WpsOffice();
  }
  return new BaseOffice();
}

/**
 * 查看原文档
 * @param bodyType
 * @param userId
 * @param zwIframe
 * @return {Promise<void>}
 */
export async function viewOffice({bodyType,userId,zwIframe}){
    return getInstance({bodyType, zwIframe}).viewOffice({bodyType,userId,zwIframe});
}

/**
 * 编辑office
 * @param bodyType
 * @param userId
 * @param zwIframe
 * @param canSign
 * @return {Promise<void>}
 */
export async function editOffice({bodyType,userId,zwIframe,canSign}){
  return getInstance({bodyType, zwIframe}).editOffice({bodyType,userId,zwIframe,canSign});
}

/**
 * 签章
 * @param bodyType
 * @param zwIframe
 * @return {Promise<Boolean>}
 */
export async function officeSignature({bodyType,zwIframe}){
  return getInstance({bodyType, zwIframe}).signature({bodyType,zwIframe});
}

/**
 * 是否是office文件类型:流式
 * @param bodyType
 * @return {boolean}
 */
export function isOfficeBodyType(bodyType){
  return ['41', '42', '43', '44'].includes(`${bodyType}`);
}

/**
 * 是否是office类型：版式 
 * pdf ofd
 * @param bodyType
 * @return {boolean}
 */
export function isVersionBodyType(bodyType){
  return ['45','46'].includes(`${bodyType}`);
}
